home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / HyperCard / USING APPS AS XCMDs / test.c < prev    next >
Text File  |  1990-06-22  |  639b  |  34 lines

  1. /* this example XXCMD returns the concatination of its parameters */
  2.  
  3. #include <Types.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. static char *result;
  8.  
  9. xxcmd_init()
  10.  
  11. {
  12.     result = NULL;
  13. }
  14.  
  15. char *xxcmd_dispatch(argc, argv)
  16. int argc;
  17. char **argv;
  18.  
  19. {
  20.     int i, n;
  21.     char **p1, *p2;
  22.     
  23.     /* find total length of argument strings (don't include XXCMD name) */
  24.     for (i = 1, n = 0, p1 = argv+1; i < argc; i++, n += strlen(*p1++)) ;
  25.     
  26.     if (result != NULL) free(result);
  27.     result = malloc(n+1);
  28.     *result = 0;
  29.     
  30.     /* concat strings together */
  31.     for (i = 1, p2 = result, p1 = argv+1; i < argc; i++,  strcpy(p2, *p1), p2 += strlen(*p1++)) ;
  32.     
  33.     return result;
  34. }